﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HtmlAgilityPack;


namespace xuanke
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.year_choose.SelectedIndex = 6;
            this.sem_choose.SelectedIndex = 1;
            UserID.Text=Licence.xuehao;
        }
        private int kb,cnt;
        private Code cd =new Code();
        private void timer_Tick(object sender, EventArgs e)
        {
            Timer_lable.Text = "" + cnt;
            while (cnt-- == 0)
            {
                timer.Enabled = false;
                OKButton.Enabled = true;
            }
        }

        private void logonwindow_NewWindow(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void login_Click(object sender, EventArgs e)
        {
            Login.Text="重新登录";
            login_browser.Dock = DockStyle.Fill;
            login_browser.Visible = true;
            Logined.Enabled = true;
            login_browser.Url = new Uri("http://tjis2.tongji.edu.cn:58080/amserver/UI/Login?goto=http%3A%2F%2Fxuanke.tongji.edu.cn%2Fpass.jsp&gotoOnFail=http%3A%2F%2Fxuanke.tongji.edu.cn%2Fdeny.jsp", System.UriKind.Absolute);
         }

        private void logout_Click(object sender, EventArgs e)
        {
            login_browser.Url = new Uri("http://xuanke.tongji.edu.cn/tj_login/logout.jsp",UriKind.Absolute);
            this.Close();
        }

        private void logined_Click(object sender, EventArgs e)
        {
            login_browser.Dock = DockStyle.None;
            login_browser.Visible =false;
            KebiaoMenu.Enabled = true;
            Logined.Enabled = false;
            query_Browser.Url = new Uri("http://xuanke.tongji.edu.cn/tj_login/redirect.jsp?link=/tj_xuankexjgl/elective/query/lessontable/kebiao.jsp?qxid=20050627993410$mkid=20050627993407&qxid=20050627993410&HELP_URL=null&MYXSJL=null", System.UriKind.Absolute);
            
        }
        /*
        private void xhcheck()
        {
            back_Browser.Url = new Uri("http://xuanke.tongji.edu.cn/tj_login/info.jsp",UriKind.Absolute);
            //back_Browser.Url = new Uri("http://liujj.orgfree.com/xiangmu.html",UriKind.Absolute);
            HtmlWeb webClient = new HtmlWeb();
            HtmlAgilityPack.HtmlDocument doc = webClient.Load("http://xuanke.tongji.edu.cn/tj_login/info.jsp");
            HtmlNode node = doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/table[1]/tr[1]/td[2]");
            textBox1.Text = node.InnerText.ToString().Substring(24,6);
            
        }
        */
        private void OKButton_Click(object sender, EventArgs e)
        {
            //query(kb);
            query_Browser.Url = new Uri(cd.kebiao(kb,xh_input.Text,int.Parse(year_choose.Text.Substring(0, 4)),int.Parse(sem_choose.Text)), System.UriKind.Absolute);
            OKButton.Enabled = false;
            timer.Enabled = true;
            cnt = Licence.timeout;
            //xm_output.Text = getstuinfo(xh_input.Text);
        }
        private void queryBrowser_NewWindow(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }
        /*
        private string getstuinfo(string xh)
        {
            info_browser.Url = new Uri("http://xuanke.tongji.edu.cn");
            info_browser.Url = new Uri("http://xuanke.tongji.edu.cn/GetXsServlet?id=" + xh);
            byte[] infobyte = System.Text.UTF8Encoding.GetEncoding("GB2312").GetBytes(info_browser.DocumentText);
            string info = Encoding.UTF8.GetString(infobyte);
            return info;
        }
        */
        private void info_browser_NewWindow(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void kebiao_xs_Click(object sender, EventArgs e)
        {
            kb = 1;
            splitContainer1.Visible = true;
            xh_lable.Text = "学号";
        }

        private void kebiao_js_Click(object sender, EventArgs e)
        {
            kb = 2;
            splitContainer1.Visible = true;
            xh_lable.Text = "工号";
        }

        private void About_Click(object sender, EventArgs e)
        {
            Form about=new About();
            about.ShowDialog();
        }
    }
}
